<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src/node/class.node.line.js - SceneGraph.js</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">

<div id="doc">
    <div id="hd" class="yui3-g header">
        <div class="yui3-u-3-4">
            
                <h1><img src="../../logo/logoCGSG_256x57.png" title="SceneGraph.js"></h1>
            
        </div>
        <div class="yui3-u-1-4 version">
            <em>API Docs for: 2.2.0</em>
        </div>
    </div>
    <div id="bd" class="yui3-g">

        <div class="yui3-u-1-4">
            <div id="docs-sidebar" class="sidebar apidocs">
                <div id="api-list">
    <h2 class="off-left">APIs</h2>
    <div id="api-tabview" class="tabview">
        <ul class="tabs">
            <li><a href="#api-classes">Classes</a></li>
            <li><a href="#api-modules">Modules</a></li>
        </ul>

        <div id="api-tabview-filter">
            <input type="search" id="api-filter" placeholder="Type to filter APIs">
        </div>

        <div id="api-tabview-panel">
            <ul id="api-classes" class="apis classes">
            
                <li><a href="../classes/CGSG.html">CGSG</a></li>
            
                <li><a href="../classes/CGSGAccordion.html">CGSGAccordion</a></li>
            
                <li><a href="../classes/CGSGAnimationManager.html">CGSGAnimationManager</a></li>
            
                <li><a href="../classes/CGSGAnimationMethod.html">CGSGAnimationMethod</a></li>
            
                <li><a href="../classes/CGSGBindEntry.html">CGSGBindEntry</a></li>
            
                <li><a href="../classes/CGSGButtonMode.html">CGSGButtonMode</a></li>
            
                <li><a href="../classes/CGSGCollisionGhostOnDemandTester.html">CGSGCollisionGhostOnDemandTester</a></li>
            
                <li><a href="../classes/CGSGCollisionManager.html">CGSGCollisionManager</a></li>
            
                <li><a href="../classes/CGSGCollisionMethod.html">CGSGCollisionMethod</a></li>
            
                <li><a href="../classes/CGSGCollisionRegionTester.html">CGSGCollisionRegionTester</a></li>
            
                <li><a href="../classes/CGSGCollisionTesterFactory.html">CGSGCollisionTesterFactory</a></li>
            
                <li><a href="../classes/CGSGColor.html">CGSGColor</a></li>
            
                <li><a href="../classes/CGSGCSSManager.html">CGSGCSSManager</a></li>
            
                <li><a href="../classes/CGSGDimension.html">CGSGDimension</a></li>
            
                <li><a href="../classes/CGSGEvent.html">CGSGEvent</a></li>
            
                <li><a href="../classes/CGSGEventManager.html">CGSGEventManager</a></li>
            
                <li><a href="../classes/CGSGHandleBox.html">CGSGHandleBox</a></li>
            
                <li><a href="../classes/CGSGImgManager.html">CGSGImgManager</a></li>
            
                <li><a href="../classes/CGSGInterpolator.html">CGSGInterpolator</a></li>
            
                <li><a href="../classes/CGSGInterpolatorLinear.html">CGSGInterpolatorLinear</a></li>
            
                <li><a href="../classes/CGSGInterpolatorTCB.html">CGSGInterpolatorTCB</a></li>
            
                <li><a href="../classes/CGSGKeyFrame.html">CGSGKeyFrame</a></li>
            
                <li><a href="../classes/CGSGMap.html">CGSGMap</a></li>
            
                <li><a href="../classes/CGSGMask.html">CGSGMask</a></li>
            
                <li><a href="../classes/CGSGMaskCache.html">CGSGMaskCache</a></li>
            
                <li><a href="../classes/CGSGMaskClip.html">CGSGMaskClip</a></li>
            
                <li><a href="../classes/CGSGMath.html">CGSGMath</a></li>
            
                <li><a href="../classes/CGSGNode.html">CGSGNode</a></li>
            
                <li><a href="../classes/CGSGNodeButton.html">CGSGNodeButton</a></li>
            
                <li><a href="../classes/CGSGNodeCircle.html">CGSGNodeCircle</a></li>
            
                <li><a href="../classes/CGSGNodeColorPicker.html">CGSGNodeColorPicker</a></li>
            
                <li><a href="../classes/CGSGNodeCurveTCB.html">CGSGNodeCurveTCB</a></li>
            
                <li><a href="../classes/CGSGNodeDomElement.html">CGSGNodeDomElement</a></li>
            
                <li><a href="../classes/CGSGNodeEllipse.html">CGSGNodeEllipse</a></li>
            
                <li><a href="../classes/CGSGNodeImage.html">CGSGNodeImage</a></li>
            
                <li><a href="../classes/CGSGNodeLine.html">CGSGNodeLine</a></li>
            
                <li><a href="../classes/CGSGNodeSlider.html">CGSGNodeSlider</a></li>
            
                <li><a href="../classes/CGSGNodeSliderHandle.html">CGSGNodeSliderHandle</a></li>
            
                <li><a href="../classes/CGSGNodeSprite.html">CGSGNodeSprite</a></li>
            
                <li><a href="../classes/CGSGNodeSquare.html">CGSGNodeSquare</a></li>
            
                <li><a href="../classes/CGSGNodeTabMenu.html">CGSGNodeTabMenu</a></li>
            
                <li><a href="../classes/CGSGNodeText.html">CGSGNodeText</a></li>
            
                <li><a href="../classes/CGSGNodeWebview.html">CGSGNodeWebview</a></li>
            
                <li><a href="../classes/CGSGParticle.html">CGSGParticle</a></li>
            
                <li><a href="../classes/CGSGParticleEmitter.html">CGSGParticleEmitter</a></li>
            
                <li><a href="../classes/CGSGParticleSystem.html">CGSGParticleSystem</a></li>
            
                <li><a href="../classes/CGSGPickNodeMethod.html">CGSGPickNodeMethod</a></li>
            
                <li><a href="../classes/CGSGPosition.html">CGSGPosition</a></li>
            
                <li><a href="../classes/CGSGRegion.html">CGSGRegion</a></li>
            
                <li><a href="../classes/CGSGRotation.html">CGSGRotation</a></li>
            
                <li><a href="../classes/CGSGScale.html">CGSGScale</a></li>
            
                <li><a href="../classes/CGSGSceneGraph.html">CGSGSceneGraph</a></li>
            
                <li><a href="../classes/CGSGSection.html">CGSGSection</a></li>
            
                <li><a href="../classes/CGSGTimeline.html">CGSGTimeline</a></li>
            
                <li><a href="../classes/CGSGTraverser.html">CGSGTraverser</a></li>
            
                <li><a href="../classes/CGSGVector2D.html">CGSGVector2D</a></li>
            
                <li><a href="../classes/CGSGView.html">CGSGView</a></li>
            
                <li><a href="../classes/CGSGWEBVIEWMODE.html">CGSGWEBVIEWMODE</a></li>
            
                <li><a href="../classes/CGSGWrapMode.html">CGSGWrapMode</a></li>
            
                <li><a href="../classes/GLOBAL_CONSTANTS.html">GLOBAL_CONSTANTS</a></li>
            
                <li><a href="../classes/GLOBAL_METHODS.html">GLOBAL_METHODS</a></li>
            
                <li><a href="../classes/GLOBAL_PROPERTIES.html">GLOBAL_PROPERTIES</a></li>
            
                <li><a href="../classes/UTIL_ARRAY.html">UTIL_ARRAY</a></li>
            
                <li><a href="../classes/WUICCGSGNodeImageFactory.html">WUICCGSGNodeImageFactory</a></li>
            
            </ul>

            <ul id="api-modules" class="apis modules">
            
                <li><a href="../modules/Animation.html">Animation</a></li>
            
                <li><a href="../modules/Collision.html">Collision</a></li>
            
                <li><a href="../modules/Math.html">Math</a></li>
            
                <li><a href="../modules/Node.html">Node</a></li>
            
                <li><a href="../modules/ParticleSystem.html">ParticleSystem</a></li>
            
                <li><a href="../modules/Scene.html">Scene</a></li>
            
                <li><a href="../modules/Util.html">Util</a></li>
            
            </ul>
        </div>
    </div>
</div>

            </div>
        </div>
        <div class="yui3-u-3-4">
                <div id="api-options">
        Show:
        <label for="api-show-inherited">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </div>


            <div class="apidocs">
                <div id="docs-main">
                    <div class="content">
                        <h1 class="file-heading">File: src/node/class.node.line.js</h1>

<div class="file">
    <pre class="code prettyprint linenums">
/**
 * A CGSGNodeLine represent a basic line
 *
 * @class CGSGNodeLine
 * @module Node
 * @extends CGSGNode
 * @constructor
 * @param {Array} points of line  as CGSGPosition
 * @type {CGSGNodeLine}
 * @author Paul Todd
 */
var CGSGNodeLine = CGSGNode.extend(
    {
        initialize: function (pts) {
            &#x27;use strict&#x27;;
            this._pts = pts.copy();
            this._nbPts = this._pts.length;
            this._minX = 0;
            this._minY = 0;
            this._maxX = 0;
            this._maxY = 0;

            this.updateMinMax();

            this._super(this._minX, this._minY, this._maxX - this._minX, this._maxY - this._minY);

            this.resizeTo(this._maxX - this._minX, this._maxY - this._minY);

            this.pickNodeMethod = CGSGPickNodeMethod.REGION;

            /**
             * @property classType
             * @readonly
             * @type {String}
             */
            this.classType = &quot;CGSGNodeLine&quot;;
        },

        /**
         * Custom rendering
         * @method render
         * @protected
         * @param {CanvasRenderingContext2D} c the context into render the node
         * */
        render: function (c) {
            c.beginPath();
            //c.globalAlpha = this.globalAlpha;

            c.moveTo(this._pts[0].x - this._minX, this._pts[0].y - this._minY);

            for (var i = 1; i &lt; this._nbPts; i++) {
                c.lineTo(this._pts[i].x - this._minX, this._pts[i].y - this._minY);
            }

            if (this.lineWidth &gt; 0) {
                c.lineWidth = this.lineWidth;
                c.strokeStyle = this.lineColor;
                c.stroke();
            }
        },

        /**
         * Replace current dimension by these new ones and compute new Points
         * @method resizeTo
         * @param {Number} w
         * @param {Number} h
         * */
        resizeTo: function (w, h) {
            this.dimension.resizeTo(w, h);

            this._computeResizedPoints();
        },

        /**
         * Multiply current dimension by these new ones
         * @method resizeTBy
         * @param wf {Number} width Factor
         * @param hf {Number} height Factor
         * */
        resizeBy: function (wf, hf) {
            this.dimension.resizeBy(wf, hf);

            this._computeResizedPoints();
        },

        /**
         * Increase/decrease current dimension with adding values
         * @method resizeWith
         * @param w {Number} width
         * @param h {Number} height
         * */
        resizeWith: function (w, h) {
            this.dimension.resizeWith(w, h);

            this._computeResizedPoints();
        },

        /**
         * @method _computeResizedPoints
         * @private
         */
        _computeResizedPoints: function () {
            var sx = this.getWidth() / (this._maxX - this._minX);
            var sy = this.getHeight() / (this._maxY - this._minY);
            var c = this.getCenter();

            if (this.getWidth() &gt; 0 &amp;&amp; this.getHeight() &gt; 0) {
                for (var i = 0; i &lt; this._nbPts; i++) {
                    this._pts[i].x = (sx * (this._pts[i].x - c.x)) + c.x;
                    this._pts[i].y = (sy * (this._pts[i].y - c.y)) + c.y;
                }
                this.updateMinMax();
            }
        },

        /**
         * Find the center of the Line
         * @public
         * @method getCenter
         */
        getCenter: function () {
            return new CGSGPosition((this._maxX - this._minX) / 2, (this._maxY - this._minY) / 2);
        },

        /**
         * Get the Largest x of the Line
         * @public
         * @method getMaxX
         */
        getMaxX: function () {
            var x = this._pts[0].copy().x, t;

            for (var i = 1; i &lt; this._nbPts; i++) {
                t = this._pts[i].copy().x;
                if (x &lt;= t) {
                    x = t;
                }
            }

            return x;
        },

        /**
         * Get the smallest x of the Line
         * @public
         * @method getMinX
         */
        getMinX: function () {
            var x = this._pts[0].copy().x, t = 0;

            for (var i = 1; i &lt; this._nbPts; i++) {
                t = this._pts[i].copy().x;

                if (x &gt;= t) {
                    x = t;
                }
            }

            return x;
        },

        /**
         * Get the Largets y of the Line
         * @public
         * @method getMaxY
         */
        getMaxY: function () {
            var y = this._pts[0].copy().y, t = 0;

            for (var i = 1; i &lt; this._nbPts; i++) {
                t = this._pts[i].copy().y;

                if (y &lt;= t) {
                    y = t;
                }
            }

            return y;
        },

        /**
         * Get the smallest y of the Line
         * @public
         * @method getMinY
         */
        getMinY: function () {
            var y = this._pts[0].copy().y, t = 0;

            for (var i = 1; i &lt; this._nbPts; i++) {
                t = this._pts[i].copy().y;

                if (y &gt;= t) {
                    y = t;
                }
            }

            return y;
        },

        /**
         * Update the min and max x/y values
         * @method updateMinMax
         */
        updateMinMax: function () {
            this._maxY = this.getMaxY();
            this._minY = this.getMinY();
            this._maxX = this.getMaxX();
            this._minX = this.getMinX();
        },

        /**
         * Set the points of the Line
         * @public
         * @method setPoints
         */
        setPoints: function (points) {
            this._pts = points.copy();
            this._nbPts = this._pts.length;
            this.updateMinMax();
            this.dimension.resizeTo(this._maxX - this._minX, this._maxY - this._minY);

            this.translateTo(this._minX, this._minY);

            /*for (var i = 0 ; i &lt; this._nbPts ; i++) {
             var p = this._pts[i];

             p.x -= this._minX;
             p.y -= this._minY;
             }*/
        },

        /**
         * Get the points of the Line
         * @public
         * @method getPoints
         */
        getPoints: function () {
            return this._pts.copy();
        },

        /**
         * Get a point of the Line at index
         * @public
         * @method getPoint
         * @param i {Number} index
         */
        getPoint: function (i) {
            if (i &lt; this._nbPts &amp;&amp; i &gt;= 0) {
                return this._pts.slice(i, i + 1).copy();
            }
            return this._pts.slice(0, 1).copy();
        },

        /**
         * @method copy
         * @return {CGSGNodeLine} a copy of this node
         */
        copy: function () {
            var node = new CGSGNodeLine(this._pts);
            //call the super method
            return this._super(node);
        }

    }
);
    </pre>
</div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>
